package com.ruoyi.web.controller.admin.construction;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.dto.ConstructionWarningConfigDTO;
import com.ruoyi.system.service.IConstructionWarningConfigService;
import com.ruoyi.system.vo.ConstructionWarningConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 施工预警配置管理控制器
 * 
 * @author ruoyi
 * @since 2024-01-01
 */
@RestController
@RequestMapping("/admin/construction/warning/config")
@Api(tags = "施工预警配置管理")
public class ConstructionWarningConfigController extends BaseController {

    @Resource
    private IConstructionWarningConfigService configService;

    /**
     * 创建预警配置
     */
    @PostMapping("/create")
    @ApiOperation("创建预警配置")
    @PreAuthorize("@ss.hasPermi('construction:warning:config:create')")
    public AjaxResult createConfig(@Validated @RequestBody ConstructionWarningConfigDTO configDTO) {
        boolean result = configService.createConfig(configDTO);
        return AjaxResult.success(result);
    }

    /**
     * 更新预警配置
     */
    @PostMapping("/update")
    @ApiOperation("更新预警配置")
    @PreAuthorize("@ss.hasPermi('construction:warning:config:update')")
    public AjaxResult updateConfig(@Validated @RequestBody ConstructionWarningConfigDTO configDTO) {
        boolean result = configService.updateConfig(configDTO);
        return AjaxResult.success(result);
    }

    /**
     * 删除预警配置
     */
    @PostMapping("/delete/{configId}")
    @ApiOperation("删除预警配置")
    @PreAuthorize("@ss.hasPermi('construction:warning:config:delete')")
    public AjaxResult deleteConfig(@PathVariable Long configId) {
        boolean result = configService.deleteConfig(configId);
        return AjaxResult.success(result);
    }

    /**
     * 获取预警配置详情
     */
    @GetMapping("/{configId}")
    @ApiOperation("获取预警配置详情")
    @PreAuthorize("@ss.hasPermi('construction:warning:config:query')")
    public AjaxResult getConfigDetail(@PathVariable Long configId) {
        ConstructionWarningConfigVO detail = configService.getConfigDetail(configId);
        return AjaxResult.success(detail);
    }

    /**
     * 获取预警配置列表
     */
    @GetMapping("/list")
    @ApiOperation("获取预警配置列表")
    @PreAuthorize("@ss.hasPermi('construction:warning:config:list')")
    public AjaxResult getConfigList(@RequestParam(required = false) String warningType) {
        List<ConstructionWarningConfigVO> list = configService.getConfigList(warningType);
        return AjaxResult.success(list);
    }

    /**
     * 启用/禁用预警配置
     */
    @PostMapping("/toggle-status/{configId}")
    @ApiOperation("启用/禁用预警配置")
    @PreAuthorize("@ss.hasPermi('construction:warning:config:update')")
    public AjaxResult toggleConfigStatus(@PathVariable Long configId, @RequestParam Boolean isEnabled) {
        boolean result = configService.toggleConfigStatus(configId, isEnabled);
        return AjaxResult.success(result);
    }
}

